package cn.geoportal.benoserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.geoportal.benoserver.entity.ConvertTaskType;
import cn.geoportal.benoserver.service.ConvertTaskTypeService;
import cn.geoportal.benoserver.mapper.ConvertTaskTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class ConvertTaskTypeServiceImpl extends ServiceImpl<ConvertTaskTypeMapper, ConvertTaskType> implements ConvertTaskTypeService{

    @Autowired
    private ConvertTaskTypeMapper convertTaskTypeMapper;

    /**
     * 1. ConvertTaskType列表
     */
    @Override
    public IPage<ConvertTaskType> selectPage(Page page, Wrapper<ConvertTaskType> wrapper) {
        return convertTaskTypeMapper.selectPage(page, wrapper);
    }

    /**
     * 2. 添加ConvertTaskType
     * @param convertTaskType
     * @return
     */
    @Override
    public int add(ConvertTaskType convertTaskType) {
        QueryWrapper<ConvertTaskType> wrapper = new QueryWrapper<>();
        wrapper.eq("name", convertTaskType.getName());
        // 如果name相同的记录已经存在则返回0
        if(convertTaskTypeMapper.selectCount(wrapper)>0){
            return 0;
        }
        return convertTaskTypeMapper.insert(convertTaskType);
    }

    /**
     * 3. 更新指定id的ConvertTaskType
     * @param convertTaskType
     * @return
     */
    @Override
    public int update(ConvertTaskType convertTaskType) {
        QueryWrapper<ConvertTaskType> wrapper = new QueryWrapper<>();
        wrapper.ne("id", convertTaskType.getId()).eq("name", convertTaskType.getName());
        // 如果name相同的记录已经存在则返回0
        if(convertTaskTypeMapper.selectCount(wrapper)>0){
            return -1;
        }
        return convertTaskTypeMapper.updateById(convertTaskType);
    }

    /**
     * 4. 获取指定id的ConvertTaskType
     * @param id
     * @return
     */
    @Override
    public ConvertTaskType findById(Integer id) {
        return convertTaskTypeMapper.selectById(id);
    }

    /**
     * 5. 删除指定id的ConvertTaskType
     * @param id
     * @return
     */
    @Override
    public int deleteById(Integer id) {
        return convertTaskTypeMapper.deleteById(id);
    }
}




